<template>
  <div>
    <el-form-item label="值信息">
      <el-select v-model="localData.bindAttrs.value" placeholder="请选择">
        <el-option v-for="item in paramList" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
      </el-select>
    </el-form-item>
    <el-form-item label="显示信息">
      <el-select v-model="localData.flowParam" placeholder="请选择">
        <el-option v-for="item in paramList" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
      </el-select>
    </el-form-item>
    <el-form-item v-for="item in bindAttrs" :key="item.value" :label="item.label">
      <el-cascader :props="CascaderProps" :options="attrList" v-model="localData.bindAttrs[item.value]" placeholder="请选择属性" filterable clearable :show-all-levels="false">
        <template #default="{ data: opt }">
          <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
        </template>
      </el-cascader>
    </el-form-item>
  </div>
</template>

<script>
export default {
  name: 'FlowStarterConfig',
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      localData: {},
      paramList: [],
      bindAttrs: [
        {
          label: '显示绑定属性',
          value: 'flowParam'
        }
      ],
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      }
    };
  },
  watch: {
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal;
          this.init();
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal);
      },
      deep: true
    }
  },
  mounted() {
    this.getDicts('code_wf_starter_list').then((res) => {
      this.paramList = res.data;
    });
  },
  methods: {
    init() {
      if (this.localData && !this.localData.bindAttrs) {
        this.localData.bindAttrs = {};
      }
    }
  }
};
</script>

<style scoped></style>
